#!/bin/env python

import time
import cv2
import numpy as np


def trackbarCallback(value):
    print(value)

windowName = "mouse"

cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
cv2.resizeWindow(windowName, 480, 640)

cv2.createTrackbar('R', windowName, 0, 255, trackbarCallback)
cv2.createTrackbar('G', windowName, 0, 255, trackbarCallback)
cv2.createTrackbar('B', windowName, 0, 255, trackbarCallback)

cv2.setTrackbarPos('R', windowName, 128)
cv2.setTrackbarPos('G', windowName, 128)
cv2.setTrackbarPos('B', windowName, 128)

img = np.zeros((480, 640, 3), np.uint8)

while True:
    r = cv2.getTrackbarPos('R', windowName)
    g = cv2.getTrackbarPos('G', windowName)
    b = cv2.getTrackbarPos('B', windowName)

    img[:] = [b, g, r]

    cv2.imshow(windowName, img)

    if cv2.waitKey(10) == ord('q'):
        break

print('销毁窗口')
cv2.destroyAllWindows()
